<template>
    <el-container class="bg-white rounded" :style="{ height: (h + 'px') }">
        <el-header class="image-header">
            <el-button type="primary" size="small" @click="handleOpenCreate">新增图片分类</el-button>
            <el-button type="warning" size="small" @click="handleOpenUpload">上传图片</el-button>
        </el-header>

        <el-container>
            <ImageAside ref="ImageAsideRef" @change="handleAsideChange" />
            <ImageMain ref="ImageMainRef" />
        </el-container>
    </el-container>
</template>

<script setup>
import { ref } from 'vue'
import ImageAside from '~/components/ImageAside.vue'
import ImageMain from '~/components/ImageMain.vue'

// 计算高度值
const windowHeight = window.innerHeight || document.body.clientHeight
const h = windowHeight - 64 - 44 - 40  // 减去头部、底部和边距的高度值

const ImageAsideRef = ref(null)

// 新增图片分类
const handleOpenCreate = () => {
    ImageAsideRef.value.handleCreate()
}

// 切换图片分类时，重新加载数据
const ImageMainRef = ref(null)
const handleAsideChange = (image_class_id) => {
    ImageMainRef.value.loadData(image_class_id)
}

// 打开上传图片对话框
const handleOpenUpload = () => {
    ImageMainRef.value.openUploadFile()
}
</script>

<style scoped>
.image-header {
    border-bottom: 1px solid #eeeeee;
    @apply flex items-center
}
</style>